﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebUI.Areas.Bots.Models;

namespace WebUI.Areas.Bots.Binders
{
    public class UsersMachinesSettingBinder : IModelBinder
    {
        private const string sessionKey = "UsersMachinesSetting";

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            UsersMachinesSetting usersMachinesSetting = (UsersMachinesSetting)controllerContext.HttpContext.Session[sessionKey];
            
            if (usersMachinesSetting == null)
            {
                usersMachinesSetting = new UsersMachinesSetting();
                controllerContext.HttpContext.Session[sessionKey] = usersMachinesSetting;
            }

            return usersMachinesSetting;
        }
    }
}